import React,{Suspense} from 'react'
import {BrowserRouter,Route,Routes,Navigate} from "react-router-dom"
import routes from "./routes"
import {routerItem} from "../interface"

const Index=()=> {
    const mapRouter=(route:routerItem[])=>{
        return route.map((v,i)=>{
            return (
                v.path?
                <Route key={i} path={v.path} element={v.element}>
                    {v.children&&mapRouter(v.children)}
                </Route>
                :<Route key={i} path={v.from} element={<Navigate to={v.to}></Navigate>}></Route>
            )
        })
    }
    return (
        <Suspense fallback={<h1>网络加载中...</h1>}>
            <BrowserRouter>
                <Routes>
                {
                    mapRouter(routes)
                }
                </Routes>
            </BrowserRouter>
        </Suspense>
    )
}

export default Index


